
var urlSplit = window.location.href.split("/");
var common = {
    prize: {},
    // urlPage: 'http://127.0.0.1:5500/static',
    url: window.location.protocol + "//" + window.location.host + "/" + urlSplit[3] + "/" + urlSplit[4],
    // url: 'http://192.168.14.184:8080/activity',
    // url: 'http://192.168.14.187:8090',
    notice1: "目前参与人数较多，请稍后再试！",
    // skipUrl: "https://live.polyv.cn/watch/239952",
};
// var dataMap = {
//     picture: ["url", "key"],

// }

$.ajax({
    type: 'get',
    url: common.url + "/external/getServerConfig",
    dataType: "json",
    success: function (data) {

        if (!data.success) {
            return;
        }

        var resp = JSON.parse(data.content.serverConfig);

        var tempKeys = [];

        for (var i = 0; i < resp.groupList.length; i++) {
            tempKeys.push(resp.groupList[i]["group_id"]);
        }
        
        for (var j = 0; j < tempKeys.length; j++) {
            var temp = resp[tempKeys[j]];
            var tempData = {};
            var tempCode = "";
            for (var k = 0; k < temp.length; k++) {

                // var keys = dataMap[temp[k]['key']]

                if (temp[k]["type"] == "picture") {
                    tempData["url"] = temp[k]["url"];
                    tempData["position"] = temp[k]["key"];
                }
                if (temp[k]["key"] == "awardsName") {
                    tempData["title"] = temp[k]["value"];
                }
                if (temp[k]["key"] == "prizeType") {
                    tempData["status"] = temp[k]["value"];
                }
                if (temp[k]["key"] == "awardsCode") {
                    tempData["awardsCode"] = temp[k]["value"];
                    tempCode = temp[k]["value"];
                }
                if (temp[k]["key"] == "skipUrl") {
                    common["skipUrl"] = temp[k]["value"];
                }
            }
        
            common.prize[tempCode] = tempData;

            common["deploycolId"] = data.content.deploycolId;
        
            // $("#" + tempData["position"]).attr("src", tempData["url"]);
            if ($("." + tempData["position"])[0] && $("." + tempData["position"])[0].tagName === "IMG" && !!tempData["url"]) {
                $("." + tempData["position"]).attr("src", tempData["url"]);
            } else if ($("." + tempData["position"])[0] && $("." + tempData["position"])[0].tagName !== "IMG" && !!tempData["url"]){
                //如果是背景图片
                $("." + tempData["position"]).css("background","url(" + tempData["url"] + ")");
                $("." + tempData["position"]).css("backgroundSize","cover");
            }

        }

        console.log(common)
    },
});